#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define EQUAL(a,b) ({a==b?1:0})
#define MAX(a,b) ({a>=b?a:b;}) //bool is undeclared in C

/*
get a random integer which is bewteen 0~max.
include time(), srand(), rand()
if called many time in a row, you will get the same number, for the time seed will stay unchanged
*/
int GetRandom(int max)
{
    time_t seed; 
	time(&seed); //set seed current time, same as seed = time(NULL)
	srand((unsigned)seed); //srand only accept unsigned int as parameter
	return rand()%max;
}

/*
the function does not return any value, but modified the content pointed by array
include qsort()
*/
int compareInt(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}

void sortInt(void * array, int len) 
{
	qsort(array, len, sizeof(int), compareInt);
}

int compareIntReverse(const void* a, const void* b)
{
	return (*(int*)b - *(int*)a);
}

void sortIntReverse(void * array, int len) 
{
	qsort(array, len, sizeof(int), compareIntReverse);
}